home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TList.h < prev    next >
Encoding:
Text File  |  1996-01-11  |  2.0 KB  |  95 lines  |  [TEXT/CWIE]

  1. //    TList.h - Macintosh Queues and Lists class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #ifndef _H_TLIST
  18. #define _H_TLIST
  19.  
  20. #include <OpenTransport.h>
  21.  
  22. class TLink
  23.     {
  24. public:
  25.         TLink()  : fNext(NULL) {};
  26.             
  27.         TLink*  Next() { return  fNext;  };
  28.  
  29.         TLink*    fNext;
  30.     };
  31.     
  32. //
  33. // TLIFO  - Atomic LIFO list
  34. //
  35. class TLifo
  36.     {
  37.     public:
  38.         TLifo()  : fHead(NULL) {};
  39.                 
  40.          void     Enqueue(TLink* link)
  41.                     { OTLIFOEnqueue((OTLIFO*)this, (OTLink*) link); }
  42.                     
  43.         TLink*    Dequeue()
  44.                     { return (TLink*)OTLIFODequeue((OTLIFO*)this); }
  45.                     
  46.         TLink*    StealList()
  47.                     { return (TLink*)OTLIFOStealList((OTLIFO*)this); }
  48.     
  49.         void     Reverse()
  50.                     {  fHead = (TLink*) OTReverseList( (OTLink*) fHead); }
  51.  
  52.         Boolean    IsEmpty()
  53.                     { return fHead == NULL; }
  54.     
  55.         TLink*    fHead;        
  56.     };
  57.  
  58.  
  59. //
  60. // TList  - Non- Atomic list management
  61. //
  62. class TList
  63.     {
  64.     public:
  65.         TList()  : fHead(NULL) {};
  66.                 
  67.          void     Add (TLink* link)
  68.                     { OTAddFirst((OTList*)this, (OTLink*) link); }
  69.                     
  70.          void     Append (TLink* link)
  71.                     { OTAddLast((OTList*)this, (OTLink*) link); }
  72.                     
  73.         TLink*    RemoveFirst ()
  74.                     { return (TLink*) OTRemoveFirst( (OTList*) this); }
  75.         
  76.         Boolean    Remove (TLink* link)
  77.                     { return OTRemoveLink((OTList*) this, (OTLink*) link); }
  78.                     
  79.         TLink*    GetFirst ()
  80.                     { return (TLink*) OTGetFirst( (OTList*) this); }
  81.                     
  82.         Boolean    IsEmpty()
  83.                     { return fHead == NULL; }
  84.         
  85.         size_t    Count();
  86.         
  87.     private:
  88.         TLink*    fHead;        
  89.     };
  90.  
  91.  
  92.  
  93.  
  94. #endif
  95.